package com.data4.supplier.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.data4.feignapi.dto.Result;
import com.data4.feignapi.dto.StandardsUpdateDTO;
import com.data4.feignapi.entity.Standards;
import com.data4.supplier.mapper.StandardsMapper;
import com.data4.supplier.service.StandardsService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Forever
 * @since 2024-12-11
 */
@Service
public class StandardsServiceImpl extends ServiceImpl<StandardsMapper, Standards> implements StandardsService {

    @Override
    public Result updateStandards(StandardsUpdateDTO standardsUpdateDTO, Integer standardsId) {
        Standards standards = BeanUtil.toBean(standardsUpdateDTO, Standards.class);
        boolean update = update(standards, new LambdaQueryWrapper<Standards>()
                .eq(Standards::getStandardId, standardsId));
        return update ? Result.ok() : Result.fail("更新失败");
    }

    @Override
    public Result getStandards(Integer standardsId) {
        Standards standards = getOne(new LambdaQueryWrapper<Standards>()
                .eq(Standards::getStandardId, standardsId));
        return Result.ok(standards);
    }
}
